//
//  MainTabBarController.swift
//  APP
//
//  Created by Rdxer on 2017/12/6.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import UIKit
import Then
import XXLogger

class MainTabBarController: XXBaseTabBarController {

//    消息  t
//    通讯录 t
//    首页 t
//    审定 v
//    我的 t
    
    var vcList:[(
        title:String,
        iconName_n:UIImage,
        iconName_h:UIImage,
        vc:UIViewController
        )] = [
//            (title: "通知", iconName_n: #imageLiteral(resourceName: "menu_消息-g"), iconName_h: #imageLiteral(resourceName: "menu_消息-r"), vc: MessageViewController.init()),
//            (title: "消息", iconName_n: #imageLiteral(resourceName: "menu_消息-g"), iconName_h: #imageLiteral(resourceName: "menu_消息-r"), vc: AddressFavoriteTableViewController.init()),
//            (title: "通讯录", iconName_n: #imageLiteral(resourceName: "menu_通讯录-g"), iconName_h: #imageLiteral(resourceName: "menu_通讯录-r"), vc: AddressBookViewController.init()),
//            (title: "首页", iconName_n: #imageLiteral(resourceName: "menu_首页-g"), iconName_h: #imageLiteral(resourceName: "menu_首页-r"), vc: IndexViewController.init()),
//            (title: "审定", iconName_n: #imageLiteral(resourceName: "menu_审定-g"), iconName_h: #imageLiteral(resourceName: "menu_审定-r"), vc: WorkViewController.init()),
//            (title: "我的", iconName_n: #imageLiteral(resourceName: "menu_我的-g"), iconName_h: #imageLiteral(resourceName: "menu_我的-r"), vc: MineViewController.init())
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.tabBar.tintColor = "#B7362C".toColor
        
        prepareChildVC()
        
        self.selectedIndex = 2
        
//        CheckUpdateManager.shared.checkIfNeed()
//        CheckAccountManager.shared.checkIfNeed()
        
        view.tintColor = AppColor.textColor
        
        ShortcutService.shared.listenAndTry(listener: self, item: .message) {[weak self] () -> (Bool) in
            self?.selectedIndex = 0
            return true
        }
        ShortcutService.shared.listenAndTry(listener: self, item: .approval) {[weak self] () -> (Bool) in
            self?.selectedIndex = 3
            return true
        }
    }
    deinit {
        ShortcutService.shared.removeListen(listener: self, item: nil)
    }
}

extension MainTabBarController{
    func prepareChildVC(){
        for item in vcList {
            item.vc.tabBarItem.image = item.iconName_n
            item.vc.tabBarItem.selectedImage = item.iconName_h
            
            item.vc.title = item.title
            
            item.vc.tabBarItem.title = item.title
            
            let nvc = XXNavigationController.init(rootViewController: item.vc)
            nvc.tabBarItem = item.vc.tabBarItem
            nvc.title = item.title
            
            addChildViewController(nvc)
        }
    }
}
